<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8">
  <title>商品列表</title>
  <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" />
  <script th:src="@{/js/jquery-3.6.0.min.js}"></script>
  <script type="text/javascript">
    function deleteGood(element) {
      const gid = element.getAttribute('data-gid');
      const goodsname = element.getAttribute('data-goodsname');

      if (confirm("确定要删除 " + goodsname + " 的记录吗？")) {
        window.location.href = '/shopping/goods/delete?gid=' + gid;
      }
    }
  </script>
</head>

<body>
<div class="panel panel-primary">
  <div class="panel-heading">
    <div th:replace="~{header}">
    </div>
  </div>
</div>
<br><br>
<div class="container">
  <div class="panel panel-primary">
    <div class="panel-heading">
      <h3 class="panel-title">商品列表</h3>
    </div>
    <div class="panel-body">
      <div>
        <button onclick="location.href='/shopping/goods/add';return false;">增加商品记录</button>
        <br><br>
      </div>
      <div class="table table-responsive">
        <table class="table table-bordered table-hover">
          <tbody class="text-center">
          <tr>
            <th>序号</th>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>价格</th>
            <th>剩余数量</th>
            <th>商品类型</th>
            <th>删除</th>
          </tr>
          <tr th:each="good,goodStat:${allGoods}">
            <td>
              <span th:text="${goodStat.count}"></span>
            </td>
            <td>
              <a th:href="@{/goods/edit(gid=${good.gid})}" th:text="${good.gid}"></a>
            </td>
            <td>
              <a th:href="@{/goods/edit(gid=${good.gid})}" th:text="${good.goodsname}"></a>
            </td>
            <td>
              <span th:text="${good.price}"></span>
            </td>
            <td>
              <span th:text="${good.stock}"></span>
            </td>
            <td>
              <span th:text="${map[good.tcode]}+'  '+${good.tcode}"></span>
            </td>
            <td>
              <a href="#" th:attr="data-gid=${good.gid}, data-goodsname=${good.goodsname}"
                 onclick="deleteGood(this)">删除</a>
            </td>

          </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
</body>

</html>